﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

using CSF.MultiLang.Data;
using CSF.MultiLang.Service;
using CSF.BusinessCore.Data;

namespace CSF.Service.Accounts.Client
{
    public class LangTextDefSvcClient : ClientBase<ILangTextDefSvc>, ILangTextDefSvc
    {
        public List<LangTextDef> GetAll()
        {
            return base.Channel.GetAll();
        }

        public LangTextDef GetOneById(int id)
        {
            return base.Channel.GetOneById(id);
        }

        public bool UpdateById(LangTextDef t, int id)
        {
            return base.Channel.UpdateById(t, id);
        }

        public bool DeleteOneById(int id)
        {
            return base.Channel.DeleteOneById(id);
        }

        public int DeleteById(IEnumerable<int> ids)
        {
            return base.Channel.DeleteById(ids);
        }

        public int Insert(LangTextDef entity)
        {
            return base.Channel.Insert(entity);
        }

        public int InsertContents(LangTextDef textDef, IEnumerable<LangTextContent> contents)
        {
            return base.Channel.InsertContents(textDef, contents);
        }

        public bool UpdateContents(IEnumerable<LangTextContent> contents, int textId, string modifyBy)
        {
            return base.Channel.UpdateContents(contents, textId, modifyBy);
        }

        public bool SaveContents<TConfig>(TConfig config, IEnumerable<LangTextContent> contents)
            where TConfig : IDataConfig, IMlDataConfig
        {
            if (config.NameTextId > 0)
            {
                return UpdateContents(contents, config.NameTextId??0, config.ModifyBy);
            }
            else
            {
                LangTextDef textDef = new LangTextDef()
                {
                    PlaceType = LangTextPlaceType.DbField,
                    Place = typeof(TConfig).Name,
                    CreateBy = config.CreateBy
                };
                int id = InsertContents(textDef, contents);
                config.NameTextId = id;
                return id > 0;
            }
        }
    }
}
